Page({
  handleSubmit(event) {
    var keyword = event.detail.value.keyword;
    wx.request({
      url: `http://192.168.4.18:3000/search?keywords=${keyword}&type=10`,
      header: {
        'content-type': 'application/json'
      },
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (res) => {
        var albums = res.data.result.albums;
        albums.forEach(item => {
          if(item.name.length>10){
            item.name = item.name.slice(0,10)+"..."
          }
          if(item.artist.name.length>7){
            item.artist.name = item.artist.name.slice(0,7)+"..."
          }
        })
        this.setData({
          result:albums
        })
      }
    });
  },

  data: {
    result:"",
    prevID:"",
    playStates:{}
  },

  handleClick(event){
    console.log(event.currentTarget.dataset);
    let id = event.currentTarget.dataset.id;
    let playStates = this.data.playStates;
    if(id !=this.data.prevID){
      playStates[id] = true;

          for(let key in playStates){
            if(key !=id){
              playStates[key] = false;
            }
          }
          this.setData({
            playStates,
            prevID:id
          })
    }else{
      playStates[id]= !playStates[id];
        this.setData({
          playStates
        })
    }
    console.log(playStates); 
  }
})



